import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'home/home.dart';
import 'news_list/news_list.dart';

class BottomBar extends StatefulWidget {
  const BottomBar({super.key});

  @override
  State<StatefulWidget> createState() {
    return _BottomBarState();
  }
}

class _BottomBarState extends State<BottomBar> {
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: IndexedStack(
            index: currentIndex,
            children: [
              MyHomePage(title: "计数器"),
              NewsList(title: "资讯"),
            ],
          )
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: currentIndex,
        items: _barItemList(),
        onTap: (index) {
          currentIndex = index;
          setState(() {});
        },
      ),
    );
  }

  List<BottomNavigationBarItem> _barItemList(){
    List<BottomNavigationBarItem> items = [];
    
    items.add(BottomNavigationBarItem(
        label: "首页",
        icon: Image.asset('assets/images/applet_followed.png', width: 32, height: 32,))
    );
    items.add(BottomNavigationBarItem(
        label: "资讯",
        icon: Image.asset('assets/images/qy_added.png', width: 32, height: 32,))
    );
    
    return items;
  }
}